//
// Copyright (c) 2009 All Right Reserved
//
// vl
//
// 2009-01-01
// Contains ...
using LargoCommon.Interfaces;
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Diagnostics.Contracts;
using System.Text;
using System.Xml.Serialization;
namespace LargoCommon.Music
{
/// Rhythmical modality.
/// Rhythmical modality is defined by its number and appropriateness
/// to rhythmical GSystem.
[Serializable]
[XmlRoot]
public sealed class RhythmicModality : BinarySchema, IRhythmic, IModalStruct
{
#region Constructors
/// Initializes a new instance of the RhythmicModality class. Serializable.
public RhythmicModality() {
}
///
/// Initializes a new instance of the RhythmicModality class.
///
/// The given system.
/// Structural code.
public RhythmicModality(GeneralSystem givenSystem, string structuralCode)
: base(givenSystem, structuralCode) {
Contract.Requires(givenSystem != null);
}
///
/// Initializes a new instance of the RhythmicModality class.
///
/// The given system.
/// Modality number.
/// Modus given as bit shift.
public RhythmicModality(GeneralSystem givenSystem, long number, byte givenBitShift)
: base(givenSystem, BinaryNumber.Transposition(givenSystem, number, givenBitShift)) {
Contract.Requires(givenSystem != null);
}
///
/// Initializes a new instance of the RhythmicModality class.
///
/// The given system.
/// Bit array.
public RhythmicModality(GeneralSystem givenSystem, BitArray givenBitArray)
: base(givenSystem, givenBitArray) {
Contract.Requires(givenSystem != null);
}
///
/// Initializes a new instance of the RhythmicModality class.
///
/// The given system.
/// Number of structure.
public RhythmicModality(GeneralSystem givenSystem, long number)
: base(givenSystem, number) {
}
/// Initializes a new instance of the RhythmicModality class.
/// Binary structure.
public RhythmicModality(BinaryStructure structure)
: base(structure) {
Contract.Requires(structure != null);
}
#endregion
#region Interface - simple properties
/// Gets schema of elements.
/// Property description.
public override string ElementSchema => this.ElementString();
#endregion
#region Interface - object properties
/// Gets rhythmical system.
/// Property description.
[XmlIgnore]
public RhythmicSystem RhythmicSystem => (RhythmicSystem)this.GSystem;
#endregion
#region Static factory methods
///
/// Get NewRhythmicModality.
///
/// The given system.
/// Structural code.
///
/// Returns value.
///
public static RhythmicModality GetNewRhythmicModality(GeneralSystem givenSystem, string structuralCode) {
Contract.Requires(givenSystem != null);
var hm = new RhythmicModality(givenSystem, structuralCode);
hm.DetermineBehavior();
return hm;
}
///
/// Get NewRhythmicModality.
///
/// The given system.
/// Structural Number.
/// Given Transposition.
///
/// Returns value.
///
public static RhythmicModality GetNewRhythmicModality(GeneralSystem givenSystem, long number, byte givenTransposition) {
Contract.Requires(givenSystem != null);
var hm = new RhythmicModality(givenSystem, number, givenTransposition);
hm.DetermineBehavior();
return hm;
}
#endregion
#region Public methods
/// Makes a deep copy of the RhythmicModality object.
/// Returns object.
public override object Clone() {
return GetNewRhythmicModality(this.GSystem, this.GetStructuralCode);
}
/// Evaluate properties of the structure.
public override void DetermineBehavior() {
this.ComputeRhythmicProperties();
}
#endregion
#region Substructures
///
/// Rhythmical Subshapes.
///
/// General Qualifier.
/// Upper limit.
/// Returns value.
public Collection Subshapes(GeneralQualifier genQualifier, int limit) {
var rv = StructuralVarietyFactory.NewRhythmicShapeModalVariety(
StructuralVarietyType.BinarySubstructuresOfModality,
this,
genQualifier,
limit);
return rv.StructList;
}
///
/// Rhythmical Subshapes.
///
/// Returns value.
public Collection Subshapes() {
var rv = StructuralVarietyFactory.NewRhythmicShapeModalVariety(
StructuralVarietyType.BinarySubstructuresOfModality,
this,
null,
10000);
return rv.StructList;
}
///
/// Rhythmical Substructures.
///
/// General Qualifier.
/// Upper limit.
/// Returns value.
public Collection Substructures(GeneralQualifier genQualifier, int limit) {
var rv = StructuralVarietyFactory.NewRhythmicStructModalVariety(
StructuralVarietyType.FiguralSubstructuresOfModality,
this,
genQualifier,
limit);
return rv.StructList;
}
///
/// Rhythmic Substructures.
///
/// Returns value.
public Collection Substructures() {
var rv = StructuralVarietyFactory.NewRhythmicStructModalVariety(
StructuralVarietyType.FiguralSubstructuresOfModality,
this,
null,
10000);
return rv.StructList;
}
#endregion
#region String representation
/// Binary schema of the structure.
/// Returns value.
public override string ElementString() {
var s = new StringBuilder();
for (byte e = 0; e < this.GSystem.Order; e++) {
s.Append(this.IsOn(e) ? 'V' : '-');
}
return s.ToString().Trim();
}
/// String representation of the object.
/// Returns value.
public override string ToString() {
var s = new StringBuilder();
s.Append("Rhythmical modality\r\n");
s.AppendLine(base.ToString());
return s.ToString();
}
#endregion
}
}